package com.question.java.time.exec02;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;

/**
 * @Description: 根据现有实例创建日期和时间
 * 问题： 用户希望修改Date-Time API 中某个类的实例
 * 方案： 如果需要进行简单的增减操作，使用plus和minus,对于其他操作使用with
 * <p>
 * 对LocalDate类进行增加操作
 * - plusDays(long daysToAdd)
 * - plusMonths(long monthsToAdd)
 * - plusMonths(long monthsToAdd)
 * - plusYears(long yearsToAdd)
 * @Author: Jun Yang
 */
public class DateTimeExample06 {
    public static void main(String[] args) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

        LocalDate startDate = LocalDate.of(2018, Month.NOVEMBER, 20);
        LocalDate endDate = startDate.plusDays(3);
        System.out.println("endDate: " + endDate.format(formatter));

        DateTimeFormatter timeFormatter = DateTimeFormatter.ISO_LOCAL_TIME;
        LocalTime startTime = LocalTime.of(17, 9, 0, 0);
        LocalTime endTime = startTime.plusNanos(1_000_000);
        endTime = endTime.minusMinutes(10);
        endTime = endTime.plusHours(1);
        System.out.println("endTime: " + endTime.format(timeFormatter));
    }
}
